<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>达之领域学习web校园管理系统</title>
  {% load static %}

  <link rel="icon" href="{% static 'images/my-da.ico' %}" type="image/x-icon">
  <link rel="stylesheet" href="{% static 'css/base.css' %}">
  <link rel="stylesheet" href="{% static 'css/index.css' %}">
  <link rel="stylesheet" href="{% static 'css/iconfont.css' %}">
  <link rel="stylesheet" href="{% static 'css/sweetalert2.css' %}">
  <script src="{% static 'js/sweetalert2.js' %}"></script>


</head>

<body>
  <div class="wrapper">
    <div class="left">
      <div class="head">
        <a href="/students/">
          <h2>学生管理系统（达之领域）</h2>
        </a>
      </div>
      <div class="profile">
        <!-- 因为登录成功后，传递了user，所以这里可以直接使用这个来获取用户名 -->
        欢迎 【{{ request.session.username }}】
        {% if request.session.user_role == 'admin' %}
        管理员
        {% elif request.session.user_role == 'student' %}
        学生
        {% else %}
        老师
        {% endif %}
      </div>
      <div class="content">
        <ul>
          {% if request.session.user_role == 'admin' %}
          <li class="active"><span class="iconfont icon-fangzi"></span>
            <a href="/grades/" class="nav-link">班级管理</a>
          </li>
          <li class="active"><span class="iconfont icon-kapian"></span>
            <a href="/teachers/">老师管理</a>
          </li>
          {% endif %}
          {% if request.session.user_role == 'admin' or request.session.user_role == 'teacher' %}
          <li><span class="iconfont icon-ren"></span>
            <a href="/students/">学生管理</a>
          </li>
          <li><span class="iconfont icon-shuben"></span>
            <a href="/scores/">成绩管理</a>
          </li>
          {% endif %}
          {% if request.session.user_role == 'student'%}
          <li><span class="iconfont icon-bianji"></span>
            <a href="{% url 'my_scores' %}">成绩列表</a>
          </li>
          {% endif %}
          <li><span class="iconfont icon-bianji"></span>
            <a href="/change_password/" id="change_password">修改密码</a>
          </li>
          <li><span class="iconfont icon-shangchuan"></span>
            <a href="/logout/" id="logout">退出登录</a>
          </li>
          <li><span>
              <img src="{% static 'images/历史记录.png' %}" alt="" width="25px" height="25px">
            </span>
            <a href="/history/">历史记录</a>
          </li>
        </ul>
      </div>
    </div>

    <script>
      document.getElementById('logout').addEventListener('click', function (event) {
        event.preventDefault()  // 阻止默认跳转
        Swal.fire({
          title: '确定要退出登录吗？',
          icon: 'warning',
          showCancelButton: true,
          confirmButtonColor: '#3085d6',
          cancelButtonColor: '#d33',
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        })
          .then((result) => {
            if (result.isConfirmed) {
              window.location.href = this.href
            }
          })
      })

      document.getElementById('change_password').addEventListener('click', function (event) {
        event.preventDefault()  // 阻止默认跳转 
        // 判断当前登录的用户名
        var username = "{{ request.session.username }}";
        // 如果是test和admin，就不允许修改密码
        console.log(username)
        if (username === 'test' || username === 'admin') {
          Swal.fire({
            title: '错误',
            text: '管理员账号不允许修改密码',
            icon: 'error',
            confirmButtonText: '确定'
          })
        } else {
          window.location.href = this.href
        }
      })
    </script>
  
    {% block content %}

    {% endblock %}
</body>

</html>